<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>管理后台</title>
    <link rel="stylesheet" type="text/css" href="../../static/semantic.min.css" th:href="@{/semantic.min.css}">
    <link rel="stylesheet" href="../../static/editormd.min.css" th:href="@{/editormd.min.css}"/>

</head>
<body>
<div class="ui borderless inverted main menu" th:replace="_fragments :: adminMenu(1,blue)">
    <div class="ui huge inverted text container">
        <a class="item active orange" href="index.html" th:href="@{/admin/index}">
            <i class="home icon"></i> 主页
        </a>
        <a class="item" href="category.html" th:href="@{/admin/category}">
            <i class="folder icon"></i> 分类
        </a>
        <a class="item" href="tags.html" th:href="@{/admin/tags}">
            <i class="tags icon"></i> 标签
        </a>
    </div>
</div>
<!--新增-->
<ui class="container" th:if="${blog.article==null}">
    <form class="ui form" th:method="post" th:action="@{/admin/blog/edit}" th:object="${blog}">
        <div class="required field" th:object="${blog.article}">
            <input type="text" class="title" name="title" placeholder="标题">
            <input type="hidden" name="author" th:value="windanchaos">
            <input type="hidden" name="des">
            <input type="hidden" name="create_time" th:value="${#dates.createNow()}">
            <input type="hidden" name="published" th:value="true">
            <div class="required field">
                <div class="" id="editor" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容" name="content" style="display: none"></textarea>
                </div>
            </div>
        </div>
        <div class="ui tow fields" th:object="${act}">
            <div class="required field">
                <div class="ui left labeled action input">
                    <label class="ui compact teal basic label">分类</label>
                    <div class="ui multiple selection dropdown">
                        <input type="hidden" name="categoryIds">
                        <div class="default text">分类</div>
                        <div class="menu">
                            <div class="item" th:each="category: ${categoryList}" th:data-value="${category.id}"
                                 th:text="${category.name}">Java编程语言
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="required field">
                <div class="ui left labeled action input">
                    <label class="ui compact teal basic label">标签</label>
                    <div class="ui selection multiple dropdown">
                        <input type="hidden" name="tagIDs">
                        <div class="default text">标签</div>
                        <div class="menu">
                            <div class="item" th:each="tags: ${tagsList}" th:data-value="${tags.id}"
                                 th:text="${tags.name}">
                                Java编程语言
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button type="submit" id="save-btn" class="ui secondary button">保存</button>
                <button type="submit" id="publish-btn" class="ui teal button">发布</button>
            </div>
        </div>
    </form>
</ui>


<!--编辑-->
<ui class="container" th:if="${blog.article!=null}">
    <form class="ui form" th:method="post" th:action="@{/admin/blog/edit}" th:object="${blog}">
        <div class="required field" th:object="${blog.article}">
            <input type="hidden"  name="id"  th:value="*{id}">
            <input type="text" class="title" name="title"  th:value="*{title}" placeholder="标题">
            <input type="hidden" name="author" th:value="windanchaos">
            <input type="hidden" name="des">
            <input type="hidden" name="create_time" th:value="${#dates.createNow()}">
            <input type="hidden" id='published' name="published" th:value="*{published}">
            <div class="required field">
                <div class="" id="editor" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容" name="content" th:text="*{content}" style="display: none"></textarea>
                </div>
            </div>
        </div>
        <div class="ui tow fields" th:object="${act}">
            <div class="required field">
                <div class="ui left labeled action input">
                    <label class="ui compact teal basic label">分类</label>
                    <div class="ui multiple selection dropdown">
                        <input type="hidden" name="categoryIds" th:value="*{categoryIds}">
                        <div class="default text">分类</div>
                        <div class="menu">
                            <div class="item" th:each="category: ${categoryList}" th:data-value="${category.id}"
                                 th:text="${category.name}">Java编程语言
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="required field">
                <div class="ui left labeled action input">
                    <label class="ui compact teal basic label">标签</label>
                    <div class="ui selection multiple dropdown">
                        <input type="hidden" name="tagIDs" th:value="*{tagIDs}">
                        <div class="default text">标签</div>
                        <div class="menu">
                            <div class="item" th:each="tags: ${tagsList}" th:data-value="${tags.id}"
                                 th:text="${tags.name}">
                                Java编程语言
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button type="submit" id="save-btn" class="ui secondary button">保存</button>
                <button type="submit" id="publish-btn" class="ui teal button">发布</button>
            </div>
        </div>
    </form>
</ui>


<script
        src="https://code.jquery.com/jquery-3.1.1.min.js"
        integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
        crossorigin="anonymous"></script>
<script src="../../static/semantic.min.js" th:src="@{/semantic.min.js}"></script>
<script src="../../static/editormd.min.js" th:src="@{/editormd.min.js}"></script>
<script type="text/javascript">
    $(function () {
        var editor = editormd("editor", {
            width: "100%",
            height: 800,
            // markdown: "xxxx",     // dynamic set Markdown text
            path: "/lib/"  // Autoload modules mode, codemirror, marked... dependents libs path
        });
    });
</script>

<script>
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });
    //搜索刷新
    $('#searchBTN').click(function () {
        var url = '/admin/blog/search';
        $.ajax({
            url: url,
            type: 'POST',
            success: function (data) {
                $("#blogList").load(data);
            }
        })
    });
    $('#save-btn').click(function () {
        $('#published').attr("value",false);
    });

</script>
</body>
</html>